package com.zrx.app.android.fragment.calculators;

import android.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.zrx.app.android.R;

import java.io.InputStream;
import java.text.DecimalFormat;
import java.util.Scanner;

/**
 * Created by liuji on 2017/7/31.
 */

public abstract class CalBase extends Fragment {
    DecimalFormat nf=new DecimalFormat("0.##");
    class  MyTextWatcher implements TextWatcher {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            calculate();
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    }

    JSONObject getTemplate(int rId) {
        InputStream res = getResources().openRawResource(rId);

        Scanner sc = new Scanner(res);
        StringBuffer sb = new StringBuffer();
        while (sc.hasNextLine())
            sb.append(sc.nextLine());
        sc.close();
        return JSON.parseObject(sb.toString(), Feature.OrderedField);
    }

    abstract void calculate();
}